#include <iostream>
class Test
{
public:
    Test()
    {
        count++;
    }
    ~Test()
    {
        count--;
    }
    static void func();
    // {
    //     std::cout << "hello world\n";
    // }

public:
    static int count; // 把变量放在静态全局区，记录有多少个对象
    int a;
};
int Test::count = 0;

/*类外定义不需要static*/
void Test::func()
{
    std::cout << "count=" << count << std::endl;
}
int main()
{
    Test *t1 = new Test();
    Test t2;
    delete t1;
    std::cout << Test::count << std::endl;
    std::cout << t1->count << std::endl;
    /*成员函数只能通过对象访问*/
    /*但是静态成员函数可以由类本身进行调用*/
    Test::func();

    return 0;
}